package com.linkhub.oms.data.sync.util;

import com.linkhub.oms.common.util.QtBeanUtil;
import com.linkhub.oms.common.util.QtStreamUtil;
import com.linkhub.oms.data.sync.api.wms.domain.dto.*;
import com.linkhub.oms.data.sync.api.wms.domain.request.*;

import java.util.List;

/**
 * @Description: WmsEntryOrderAssist
 * @Author: echo
 * @Date: 2024/5/6 21:22
 * @Version: 1.0
 */
public class WmsEntryOrderAssist {


    public static EntryOrderCreateRequest convertEntryOrderRequest( WmsEntryOrderDTO entryOrderDTO ) {
        EntryOrderCreateRequest.Request.EntryOrder entryOrder = convertEntryOrder(entryOrderDTO);
        EntryOrderCreateRequest.Request.OrderLines orderLines = convertEntryOrderLines(entryOrderDTO.getOrderLines());
        return EntryOrderCreateRequest.createRequest(entryOrder, orderLines);
    }

    public static EntryOrderCreateRequest.Request.EntryOrder convertEntryOrder( WmsEntryOrderDTO entryOrderDTO ) {
        EntryOrderCreateRequest.Request.EntryOrder entryOrder = new EntryOrderCreateRequest.Request.EntryOrder();
        QtBeanUtil.copyProperties(entryOrderDTO, entryOrder);
        return entryOrder;
    }

    public static EntryOrderCreateRequest.Request.OrderLines convertEntryOrderLines( List<WmsEntryOrderLineDTO> orderLines ) {
        EntryOrderCreateRequest.Request.OrderLines entryOrderLines = new EntryOrderCreateRequest.Request.OrderLines();
        entryOrderLines.setOrderLine(QtStreamUtil.map(orderLines, WmsEntryOrderAssist::convert));
        return entryOrderLines;
    }

    private static EntryOrderCreateRequest.Request.OrderLines.OrderLine convert( WmsEntryOrderLineDTO orderLineDTO ) {
        EntryOrderCreateRequest.Request.OrderLines.OrderLine orderLine = new EntryOrderCreateRequest.Request.OrderLines.OrderLine();
        QtBeanUtil.copyProperties(orderLineDTO, orderLine);
        return orderLine;
    }

    public static SyncProductRequest convertSyncProductRequest( WmsSyncProductDTO wmsSyncProductDTO, String customerId, String warehouseCode, String supplierCode, String supplierName ) {
        SyncProductRequest.Request.Item item = convertItem(wmsSyncProductDTO);


        // 暂时不需要拓展参数
        // SyncProductRequest.Request.ExtendProps extendProps = convertExtendProps(wmsSyncProductDTO);
        return SyncProductRequest.createRequest(item, null, customerId, warehouseCode, supplierCode, supplierName);
    }

    private static SyncProductRequest.Request.Item convertItem( WmsSyncProductDTO wmsSyncProductDTO ) {
        SyncProductRequest.Request.Item item = new SyncProductRequest.Request.Item();
        QtBeanUtil.copyProperties(wmsSyncProductDTO, item);
        return item;
    }

    public static SyncProductRequest convertSyncProductRequest( WmsSyncProductDTO wmsSyncProductDTO){
        return SyncProductRequest.createSyncProductRequest(wmsSyncProductDTO);
    }

    public static EntryOrderBatchCreateRequest convertEntryOrderBatchCreateRequest( WmsEntryOrderBatchCreateDTO wmsEntryOrderBatchCreateDTO ) {
        return EntryOrderBatchCreateRequest.createRequest(wmsEntryOrderBatchCreateDTO);
    }

    public static BatchCancelOrderRequest convertBatchCancelOrderRequest( WmsCancelOrderDTO wmsCancelOrderDTO ) {
        return BatchCancelOrderRequest.createRequest(wmsCancelOrderDTO);
    }

    public static StockOutBatchCreateRequest convertStockOutBatchCreateRequest( WmsStockOutBatchCreateDTO wmsCreateDeliveryListDTO ) {
        return StockOutBatchCreateRequest.createRequest(wmsCreateDeliveryListDTO);
    }

    public static StoreProcessCreateRequest convertCreateStoreProcessRequest( WmsProcessOrderCreateDTO wmsProcessOrderCreateDTO ) {
        return StoreProcessCreateRequest.createRequest(wmsProcessOrderCreateDTO);
    }
}
